package com.sgb.goods.widget.pop;

import android.content.Context;

import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.entity.IpPickSelectEntity;
import com.sgb.goods.utils.base.adapter.RecordPointCommonAdapter;
import com.swgk.core.dialog.PopViewHolder;

import java.util.List;

public class GoodsStatusPopWindow extends GoodsPopWindow {

    public RecordPointCommonAdapter<IpPickSelectEntity> adapter;

    public GoodsStatusPopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        adapter = new RecordPointCommonAdapter<IpPickSelectEntity>(R.layout.goods_item_goods_status_select, BR.viewModel) {
            @Override
            public boolean equivalentToObject(IpPickSelectEntity object1, IpPickSelectEntity object2) {
                if(null == object1 || null == object2) {
                    return false;
                }
                return null != object1.id && object1.id.equals(object2.id);
            }
        };
        return R.layout.goods_pop_ip_window;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        holder.setBinding(BR.ipw, this);

        // 关闭
        holder.getPop().findViewById(R.id.ll).setOnClickListener(view -> {
            dissMiss();
        });

        // 确认
        adapter.setItemClickListener((adapter2, view, position) -> {
            if (onResultClick != null) {
                onResultClick.result(adapter.getData().get(position), position, null);
            }
            adapter.setRecordPoint();
            dissMiss();
        });
    }

    public void setData(List<IpPickSelectEntity> list) {
        // 设置选中默认项为第一项
        adapter.setDefaultItem(true);
        adapter.setNewData(list);
    }
}
